package day04;

import org.apache.commons.codec.binary.Hex;
import org.apache.commons.codec.digest.DigestUtils;

import java.nio.charset.StandardCharsets;
import java.util.Base64;

public class Demo04 {
    public static void main(String[] args) {
        /*
         * Base64 的用途
         */
        String str = "123456";
        byte[] bytes = str.getBytes(StandardCharsets.UTF_8);
        byte[] arr = DigestUtils.getSha256Digest().digest(bytes);
        //将加密后的数据 arr 转换为字符串
        String hex = Hex.encodeHexString(arr);
        String base64 = Base64.getEncoder().encodeToString(arr);
        System.out.println(hex);
        System.out.println(base64);

    }
}
